﻿Public Class frmSelections
    Public pChoix As String

    Private szSQL As String
    Private rs As ADODB.Recordset = Nothing


    Private Sub frmSelections_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        Me.Text = pChoix
        Select Case pChoix
            Case "NO AGREMENT"
                Call InitListeAgrement()
        End Select
        ' efface le paramètre de retour
        pChoix = ""

    End Sub

    Private Sub InitListeAgrement()
        Dim nb As Integer = 0

        ' effacer la listview
        LV_LISTE.Items.Clear()

        ' affiche les 50 CABINETS à partir de l'élève courant
        szSQL = "CALL spGET_CLIENTSbyAGREMENT('" & gSocieteCode & "')"
        GetRecordset(ctDSN_DEVFAC, szSQL, rs)

        Do While Not rs.EOF
            LV_LISTE.Items.Add(rs.Fields("agrement").Value)
            LV_LISTE.Items(nb).SubItems.Add(rs.Fields("nom").Value)
            nb = nb + 1
            ' Get the next record
            rs.MoveNext()
        Loop
        ' Close the recordset AND connection.
        rs.Close()
        setIndice(0, LV_LISTE)

    End Sub

    Private Sub LV_LISTE_DoubleClick(sender As Object, e As System.EventArgs) Handles LV_LISTE.DoubleClick

        If LV_liste.SelectedItems.Count > 0 Then
            ' afficher les détails 
            pChoix = LV_LISTE.SelectedItems(0).Text
            Me.Close()
        End If

    End Sub

    Private Sub LV_LISTE_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles LV_LISTE.KeyDown

        Select Case e.KeyCode
            Case Keys.Enter         ' Enter = DoubleClick
                LV_LISTE_DoubleClick(sender, e)

        End Select

    End Sub
End Class